#!/bin/bash

# Function to format .go files in a directory recursively
format_go_files() {
    local dir="$1"

    # Loop through all files and directories in the current directory
    for file in "$dir"/*; do
        if [[ -d "$file" ]]; then
            # Skip the vendor directory
            if [[ "${file##*/}" == "vendor" ]]; then
                continue
            fi
            # Recursively call format_go_files for subdirectories
            format_go_files "$file"
        elif [[ -f "$file" && "${file: -3}" == ".go" ]]; then
            echo "Formatting $file ..."
            gofmt -w "$file"
        fi
    done
}

# Starting from the current directory
start_dir=$(pwd)

# Call the function to format .go files recursively
format_go_files "$start_dir"

echo "Go formatting completed."

